﻿using System;
using RpcModular.Model;

namespace RpcModular
{
    /// <summary>
    /// 授权服务模块
    /// </summary>
    public interface IAccreditService
    {
        /// <summary>
        /// 当前登陆的授权码
        /// </summary>
        Guid? AccreditId
        {
            get;
        }
        /// <summary>
        /// 当前登陆用户
        /// </summary>
        IUserState CurrentUser { get; }
        /// <summary>
        /// 添加授权
        /// </summary>
        /// <param name="applyId">用户唯一标识码</param>
        /// <param name="roleId">拥有的角色ID</param>
        /// <param name="state">注册的状态数据</param>
        /// <param name="expire">授权有效期(秒)</param>
        /// <returns>授权码</returns>
        Guid AddAccredit(string applyId, string[] roleId, UserState state, int? expire=null);
        /// <summary>
        /// 申请临时授权码
        /// </summary>
        /// <param name="role">临时授权的角色</param>
        /// <param name="isInherit">是否继承上级授权码的状态和权限</param>
        /// <param name="expire">授权有效期(秒)</param>
        /// <returns>临时授权码</returns>
        Guid ApplyTempAccredit(string[] role, bool isInherit, int? expire = null);

        Guid ApplyTempAccredit(string applyId, string[] roleId, UserState state, bool isInherit, int? expire = null);
        /// <summary>
        /// 取消授权
        /// </summary>
        /// <param name="accreditId">授权码</param>
        void CancelAccredit(Guid accreditId);
        /// <summary>
        /// 踢出授权用户
        /// </summary>
        /// <param name="applyId">用户唯一标识码</param>
        void KickOutAccredit(string applyId);

        /// <summary>
        /// 更新授权状态
        /// </summary>
        /// <param name="accreditId">授权码</param>
        /// <param name="state">授权状态</param>
        /// <param name="roleId">角色类型</param>
        /// <param name="expire">授权过期时间(秒)</param>
        void ToUpdate(Guid accreditId, UserState state, string[] roleId, int? expire = null);

        /// <summary>
        /// 检查是否授权
        /// </summary>
        /// <param name="accreditId">授权码</param>
        /// <returns>是否授权</returns>
        bool CheckIsAccredit(Guid accreditId);
        /// <summary>
        /// 检查授权状态
        /// </summary>
        /// <param name="accreditId">授权码</param>
        void CheckAccredit(Guid accreditId);
        /// <summary>
        /// 获取授权的状态数据
        /// </summary>
        /// <param name="accreditId">授权码</param>
        /// <returns>注册的授权状态信息</returns>
        IUserState GetAccredit(Guid accreditId);

        /// <summary>
        /// 设置当前授权码
        /// </summary>
        /// <param name="accreditId"></param>
        void SetCurrentAccredit(Guid accreditId);
    }
}